home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / dfpp01.zip / STATBAR.CPP < prev    next >
C/C++ Source or Header  |  1992-11-21  |  2KB  |  77 lines

  1. // ------------- statbar.cpp
  2.  
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include "statbar.h"
  6.  
  7. StatusBar::StatusBar(DFWindow *par)    : TextBox( par->ClientLeft(),
  8.                                                 par->Bottom(),
  9.                                                   1,
  10.                                                   par->ClientWidth(),
  11.                                                   par)
  12. {
  13.     windowtype = StatusbarWindow;
  14.     SetAttribute(FRAMEWND);
  15.     SetColors();
  16. }
  17.  
  18. StatusBar::~StatusBar()
  19. {
  20. }
  21.  
  22. // -------- set the fg/bg colors for the window 
  23. void StatusBar::SetColors()
  24. {
  25.     colors.fg = BLACK;
  26.     colors.bg = CYAN;
  27. }
  28.  
  29. void StatusBar::ParentSized(int xdif, int ydif)
  30. {
  31.     Size(Right()+xdif, Top());
  32.     Move(Left(), Bottom()+ydif);
  33. }
  34.  
  35. void StatusBar::ClockTick()
  36. {
  37.     static Bool flipflop = False;
  38.     time_t t = time(NULL);
  39.     struct tm *now = localtime(&t);
  40.     int hr = now->tm_hour > 12 ?
  41.             now->tm_hour - 12 :
  42.             now->tm_hour;
  43.     if (hr == 0)
  44.         hr = 12;
  45.     int mn = now->tm_min;
  46.     char hm[3];
  47.     itoa(hr, hm, 10);
  48.     String timestr(hm);
  49.     timestr += ":";
  50.     if (mn < 10)
  51.         timestr += "0";
  52.     itoa(mn, hm, 10);
  53.     timestr += hm;
  54.     timestr += (now->tm_hour > 11 ? "pm " : "am ");
  55.     timestr += " ";
  56.     /* ------- blink the : at one-second intervals ----- */
  57.     if (flipflop)    {
  58.         timestr[hr < 10 ? 1 : 2] = ' ';
  59.         flipflop = False;
  60.     }
  61.     else
  62.         flipflop = True;
  63.     int x = ClientWidth() - 8;
  64.     Dequeue();
  65.     Enqueue();
  66.     WriteClientString(timestr, x, 0, colors.fg, colors.bg);
  67. }
  68.  
  69. void StatusBar::StatusMessage(String& Msg)
  70. {
  71.     int x = (ClientWidth() - Msg.Strlen()) / 2;
  72.     WriteClientString(Msg, x, 0, colors.fg, colors.bg);
  73. }
  74.  
  75.  
  76.  
  77.